/*
    Copyright Nicolas Ronvel 2007
	gulix33xp@yahoo.fr

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

using System;

namespace BlindShark
{
	/// <summary>
	/// Description of TimeEvent.
	/// </summary>
	public class TimeEvent : IComparable
	{
		public delegate void Call();
		
		#region Variables
		private float timeLeft;
		private float length;
		
		private bool dead;
		private bool immortal;
		private int lifeLeft;
		
		private bool paused;
		
		private Call call;
		#endregion
		
		#region Properties
		public bool IsDead
		{
			get {return dead;}
		}
		
		public bool IsPaused
		{
			get {return paused;}
			set {paused = value;}
		}
		
		public float TimeLeft
		{
			get {return timeLeft;}
		}
		
		public bool IsImmortal
		{
			get {return immortal;}
		}
		#endregion
		
		public TimeEvent(int repeatNumber, float delayToCall, Call c)
		{
			length = delayToCall;
			timeLeft = length;
			dead = false;
			immortal = false;
			lifeLeft = repeatNumber;
			paused = false;
			call = new Call(c);
		}
		
		public TimeEvent(float delayToCall, Call c)
		{
			length = delayToCall;
			timeLeft = length;
			dead = false;
			immortal = true;
			lifeLeft = 0;
			paused = false;
			call = new Call(c);
		}
		
		public int CompareTo(object rhs)
		{
			TimeEvent t = (TimeEvent) rhs;
			return this.timeLeft.CompareTo(t.timeLeft);
		}
		
		public void SpendTime(float time)
		{
			timeLeft -= time;
		}
		
		public void ExecCall()
		{
			call();
		}
		
		public void DecreaseLife()
		{
			lifeLeft--;
			if (lifeLeft<=0)
				dead=true;
		}
		
		public void Reset()
		{
			timeLeft = length;
		}
	}
}
